package com.lvyq.myplayer.ui.fragment

import android.view.View
import android.view.View.*
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.lvyq.myplayer.R
import com.lvyq.myplayer.adapter.MvPagerAdapter
import com.lvyq.myplayer.base.BaseFragment
import com.lvyq.myplayer.model.area.MvAreaBean
import com.lvyq.myplayer.presenter.impl.MvPresenterImpl
import com.lvyq.myplayer.view.MvView
import org.jetbrains.anko.find

/**
 * 文件描述：HomeFragment
 * 作者：lvyq
 * 创建时间：2025-02-13
 * 修改时间：2025-02-13
 */
class MvFragment: BaseFragment(), MvView {

    lateinit var  viewPager : ViewPager
    lateinit var tabLayout :TabLayout

    val presenter by lazy { MvPresenterImpl(this) }
    override fun initView(): View? {
        var view = View.inflate(context, R.layout.fragment_video, null)
        viewPager =  view.find<ViewPager>(R.id.viewPager)
        tabLayout= view.findViewById<TabLayout>(R.id.tabLayout)
        return view
    }

    override fun initData() {
        //加载区域数据
        presenter.loadDatas()
    }

    override fun initListener() {

    }

    override fun onSuccess(result: MvAreaBean) {
        //在fragement中管理Fragement用Child
        val  adapter = MvPagerAdapter(result,childFragmentManager)
        viewPager.adapter=adapter
        //tabLayout 设置
        tabLayout.setupWithViewPager(viewPager)

    }

    override fun onError(msg: String) {
        myToast("获取数据异常")
    }

}